/**
 * Handle changed data.
 *
 * @param {Object} oldValue old value
 * @param {Object} newValue new value
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"1AB88030-01C5-40AE-A0F4-894F880AB47F"}
 */
function onDataChange_codigo(oldValue, newValue, event) {
	if (controller.getSelectedIndex() == 1 && globals.gEstadoAbm == 1)
	{
		elements.nombre.requestFocus()
		return true
	}
	else
	{
		elements.nombre.requestFocus()
		legajo = oldValue
		return true
	}
}

/**
 * @properties={typeid:24,uuid:"53CB8842-B6E6-4E21-8591-597B010E2F6D"}
 */
function validar() {
	controller.setSelectedIndex(1)
	if (globals.gEstadoAbm == 1)
	{
		var $sql = 'SELECT legajo FROM personal WHERE legajo = ? AND empresa = ?'
		var $args = [legajo, globals.gUservID]
		var $ds = databaseManager.getDataSetByQuery('contable',$sql,$args,-1)
		if ($ds.getMaxRowIndex() != 0) 
		{		
			return [false, false, "El legajo ingresado ya existe"]
		}
	}
	return [true]
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"B0FD6DBF-5699-4B35-9D79-29ADCA08F225"}
 */
function onShow(firstShow, event) {
	controller.sort("legajo asc")
}

/**
 * @properties={typeid:24,uuid:"EA40B9A6-3B9C-4B90-8E92-1ACE02D183D8"}
 */
function imprimir()
{
	//forms.legajos_impresion.controller.showPrintPreview()
	jasper('impresion')
}

/**
 * @properties={typeid:24,uuid:"738A6293-337D-461C-802F-1CD585E64FF0"}
 */
function pdf()
{
	//globals.metodoPdf('legajos_impresion','legajos - '+globals.glegajo ,true)
	jasper('pdf')
}

/**
 * @properties={typeid:24,uuid:"931487BA-566D-445C-AE5C-AFBBE041DF06"}
 */
function xls()
{
	jasper('xls')
}

/**
 * @properties={typeid:24,uuid:"5233F857-7252-4D4F-8751-8942A5BF7F77"}
 */
function csv()
{
	jasper('csv')
}

/**
 * @param {String} tipo
 * @properties={typeid:24,uuid:"23F8430A-89EB-4BEE-95F0-7E62FF881B73"}
 */
function jasper(tipo)
{
	var $params = {
		userv: usuarios_to_uservs.razon_social
	}
	
	globals.metodoJasper(tipo,'contable/legajos.jasper','Legajos',foundset,$params)
}